<script type="text/javascript">
    function deleteProduct(el, id){
        var a = new AlertInfo();
        a.show();
        
        var myRequest = new Request({
            url: BASE_URL+'/items/deleteproduct/'+id,
            method: 'post',
            onSuccess: function(response){
                el.getParent('tr').destroy();
                a.hide();
            },
            onFailure: function(response){
                a.error();
            },
            onComplete: function(response){
            },
            onCancel: function(){
                a.hide();
            }
        }).send();
    }
</script>

<div class="sheet-container">
    <div class="sheet-container-wrap">
        <h2>Produkty</h2>
        <div>
            <table class="list-table table-sortable" style="width: 100%;">
                <thead>
                    <tr>
                        <th style="width: 30px;">Lp</th>
                        <th>Nazwa</th>
                        <th>Kategoria</th>
                        <th>Producent</th>
                        <th>Cena</th>
                        <th>Opcje</th>
                    </tr>
                </thead>
                <tbody>
                    <? foreach ($data as $v): ?>
                        <tr>
                            <td><?= ++$lp; ?></td>
                            <td><?= $v['name'] ?></td>
                            <td><?= $v['category'] ?></td>
                            <td><?= $v['producer'] ?></td>
                            <td><?= $v['price'] ?></td>
                            <td>
                                <a target="" class="span-imglink sprite sprite-pencil" title="edytuj" href="<?= URL::site('items/additem/' . $v['id']) ?>"></a>
                                <span class="span-imglink sprite sprite-sign_remove" 
                                      onclick="
                                          if(confirm('Na pewno chcesz usunąć ? (trwałe usunięcie)')){
                                              deleteProduct(this, <?= $v['id'] ?>);
                                          }
                                      " 
                                      style="margin-left: 20px;" 
                                      title="usuń"
                                      >
                                    usuń
                                </span>
                            </td>
                        </tr>
                    <? endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

